package sctu.edu.java.year2016.team06.chenqiang.day20160601.chapter10_3;

/**
 * Created by XQ on 2016/6/1.
 * 创建Map集合，创建Emp对象，并将创建的Emp对象添加到集合中，并将id为005的对象从集合中移除。
 */

import java.util.*;

public class Remove {
    public static void main(String[] args) {
        Map map = new HashMap();
        Emp emp = new Emp("001", "张同学");
        Emp emp1 = new Emp("003", "陈同学");
        Emp emp2 = new Emp("005", "周同学");
        map.put(emp.getId(), emp.getName());
        map.put(emp1.getId(), emp1.getName());
        map.put(emp2.getId(), emp2.getName());
        Set set = map.keySet();
        System.out.println("The original element in the map collection:");
        Iterator it = set.iterator();
        while (it.hasNext()) {
            String id = (String) it.next();
            String name = (String) map.get(id);
            System.out.println(id + " " + name);
        }
       /* map.remove("005");
        System.out.println("Map collection after the deletion of the elements:");
        System.out.println(map);*/
        Iterator it1 = map.keySet().iterator();
        while (it1.hasNext()) {
            String key = (String) it1.next();
            if ("005".equals(key)) {
                it1.remove();
                map.remove(key);
            }
        }
        System.out.println("Map collection after the deletion of the elements:");
        Iterator it2 = set.iterator();
        while (it2.hasNext()) {
            String id = (String) it2.next();
            String name = (String) map.get(id);
            System.out.println(id + " " + name);
        }
    }
}
